﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using NBA.Entity;
using NBA.DBUtility;

namespace NBA.DataAccess
{
    public class DaTeamStats
    {
        public List<TeamStat> GetTeamStatsByTeamId(string teamId)
        {
            string sql = string.Format("SELECT * FROM TeamStats WHERE TeamId='{0}'", teamId);
            return NbaEntityHelper<TeamStat>.GetEntitySet(sql);
        }        

        public List<TeamStat> GetTeamStatsAverage(string teamId)
        {
            string str = "SELECT [TeamId], AVG([Shot2]) AS [Shot2], AVG([Goal2]) AS [Goal2]," +
                " AVG([Shot3]) AS [Shot3], AVG([Goal3]) AS [Goal3], AVG([FreeThrow]) AS [FreeThrow]," +
                " AVG([FreeThrowGoal]) AS [FreeThrowGoal], AVG([OffensiveRebound]) AS [OffensiveRebound]," +
                " AVG([DefensiveRebound]) AS [DefensiveRebound], AVG([Assist]) AS [Assist]," +
                " AVG([Foul]) AS [Foul], AVG([Steal]) AS [Steal], AVG([Turnover]) AS [Turnover]," +
                " AVG([Block]) AS [Block], AVG([Scoring]) AS [Scoring], " +
                " FROM [NBA].[dbo].[TeamStats] " +
                " WHERE TeamId='{0}' AND OT=0 " +
                " GROUP BY TeamId";
            string sql = string.Format(str, teamId);
            return NbaEntityHelper<TeamStat>.GetEntitySet(sql);
        }
    }
}
